package cn.iocoder.yudao.module.knowledge.service.elecdataln;

import cn.hutool.core.collection.CollUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.knowledge.controller.admin.elecdataln.vo.*;
import cn.iocoder.yudao.module.knowledge.dal.dataobject.elecdataln.ElecDataLnDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.knowledge.dal.mysql.elecdataln.ElecDataLnMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList;
import static cn.iocoder.yudao.module.knowledge.enums.ErrorCodeConstants.*;

/**
 * 用电信息查询 Service 实现类
 *
 * @author 超级管理员
 */
@Service
@Validated
public class ElecDataLnServiceImpl implements ElecDataLnService {

    @Resource
    private ElecDataLnMapper elecDataLnMapper;

    @Override
    public Long createElecDataLn(ElecDataLnSaveReqVO createReqVO) {
        // 插入
        ElecDataLnDO elecDataLn = BeanUtils.toBean(createReqVO, ElecDataLnDO.class);
        elecDataLnMapper.insert(elecDataLn);

        // 返回
        return elecDataLn.getId();
    }

    @Override
    public void updateElecDataLn(ElecDataLnSaveReqVO updateReqVO) {
        // 校验存在
        validateElecDataLnExists(updateReqVO.getId());
        // 更新
        ElecDataLnDO updateObj = BeanUtils.toBean(updateReqVO, ElecDataLnDO.class);
        elecDataLnMapper.updateById(updateObj);
    }

    @Override
    public void deleteElecDataLn(Long id) {
        // 校验存在
        validateElecDataLnExists(id);
        // 删除
        elecDataLnMapper.deleteById(id);
    }

    @Override
        public void deleteElecDataLnListByIds(List<Long> ids) {
        // 删除
        elecDataLnMapper.deleteByIds(ids);
        }


    private void validateElecDataLnExists(Long id) {
        if (elecDataLnMapper.selectById(id) == null) {
            throw exception(ELEC_DATA_LN_NOT_EXISTS);
        }
    }

    @Override
    public ElecDataLnDO getElecDataLn(Long id) {
        return elecDataLnMapper.selectById(id);
    }

    @Override
    public PageResult<ElecDataLnDO> getElecDataLnPage(ElecDataLnPageReqVO pageReqVO) {
        return elecDataLnMapper.selectPage(pageReqVO);
    }

}